package reflect;

import java.util.ArrayList;
import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入类名");
        String className=scan.nextLine();
        Class cls=Class.forName(className);

        /*
        通过newInstance()可以进行实例化
        假设cls为String对象，则newInstance()的结果相当于String s=new String();
        假设cls为ArrayList对象，则newInstance()的结果相当于ArrayList list=new ArrayList();
        */
        Object obj=cls.newInstance();
        System.out.println(obj);


    }
}
